package cn.chason678.springbootwebdemo.service.impl;

import cn.chason678.springbootwebdemo.cn.entity.ProDeviceCn;
import cn.chason678.springbootwebdemo.cn.entity.ProDeviceCnExample;
import cn.chason678.springbootwebdemo.cn.repository.ProDeviceCnMapper;
import cn.chason678.springbootwebdemo.en.entity.ProDeviceEn;
import cn.chason678.springbootwebdemo.en.entity.ProDeviceEnExample;
import cn.chason678.springbootwebdemo.en.repository.ProDeviceEnMapper;
import cn.chason678.springbootwebdemo.service.DevcieService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * @Author: chason
 * @Date: 2024/1/19 14:46
 * @Description:
 */
@Service
public class DevcieServiceImpl implements DevcieService {
    @Autowired
    ProDeviceCnMapper proDeviceCnMapper;
    @Autowired
    ProDeviceEnMapper proDeviceEnMapper;

    public ProDeviceCn getDeviceCnByOnlyCode(String onlyCode) {
        if (StringUtils.isEmpty(onlyCode)) {
            return null;
        }

        ProDeviceCnExample example = new ProDeviceCnExample();
        ProDeviceCnExample.Criteria criteria = example.createCriteria();
        criteria.andOnlyCodeEqualTo(onlyCode);

        List<ProDeviceCn> list = proDeviceCnMapper.selectByExample(example);
        if (CollectionUtils.isEmpty(list)) {
            return null;
        }

        return list.get(0);
    }

    public ProDeviceEn getDeviceEnByOnlyCode(String onlyCode) {
        if (StringUtils.isEmpty(onlyCode)) {
            return null;
        }

        ProDeviceEnExample example = new ProDeviceEnExample();
        ProDeviceEnExample.Criteria criteria = example.createCriteria();
        criteria.andOnlyCodeEqualTo(onlyCode);

        List<ProDeviceEn> list = proDeviceEnMapper.selectByExample(example);
        if (CollectionUtils.isEmpty(list)) {
            return null;
        }

        return list.get(0);
    }
}
